class Solution
{
public:
    int countWords(vector<string> &words1, vector<string> &words2)
    {
        unordered_map<string, int> words1Count;
        unordered_map<string, int> words2Count;
        for (string &word : words1)
        {
            ++words1Count[word];
        }
        for (string &word : words2)
        {
            ++words2Count[word];
        }
        int bothOnceCount = 0;
        for (auto &[word, count] : words1Count)
        {
            if (count == 1 && words2Count[word] == 1)
            {
                ++bothOnceCount;
            }
        }
        return bothOnceCount;
    }
};